package com.tao.YanMoDesignPattern.Mediator.case1_mainbox;


/**
 * @Author Mi_Tao
 * @Date 2023/7/23
 * @Description
 * @Version 1.0
 **/
public class MainBoard implements Mediator{
    // 需要知道要交互的同事类
    private CPU cpu = null;
    private CDDriver cdDriver = null;
    private SoundCard soundCard = null;
    private ViedoCard viedoCard = null;
    @Override
    public void changed(Colleague colleague) {
        if (colleague == cdDriver){
            // 光驱读取数据
            this.opeCDDriverReadDate((CDDriver)colleague );
        }if (colleague == cpu){
            // 表示CPUU 处理完了
            this.opeCPU((CPU)colleague);
        }
    }

    /**
     * 处理光驱读取数据以后与其他对象的交互
     *
     * @param cd cd
     */
    private void opeCDDriverReadDate(CDDriver cd){
        // 1 先获取光驱读取的数据
        String date = cd.getDate();
        // 2 把这些数据传递给CPU 处理
        this.cpu.executeData(date);
    }

    public void opeCPU(CPU cpu){
        // 1先获取CPU处理后的数据
        String videoDate = cpu.getVideoDate();
        String soudDate = cpu.getSoudDate();
        // 2把这些数据传递给显卡和声卡
        this.viedoCard.showData(videoDate);
        this.soundCard.showData(soudDate);
    }

    public void setCpu(CPU cpu) {
        this.cpu = cpu;
    }

    public void setCdDriver(CDDriver cdDriver) {
        this.cdDriver = cdDriver;
    }

    public void setSoundCard(SoundCard soundCard) {
        this.soundCard = soundCard;
    }

    public void setViedoCard(ViedoCard viedoCard) {
        this.viedoCard = viedoCard;
    }
}
